package org.xutils.db.model;

import java.util.Objects;

/**
 * Created by ZZH on 4/19/21.
 *
 * @Date: 4/19/21
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description:
 */
public class KeyValue {
    public final String key;
    public final Object value;
    public final boolean autoGen;

    public KeyValue(String key, Object value) {
        this(key, value, false);
    }

    public KeyValue(String key, Object value, boolean autoGen) {
        this.key = key;
        this.value = value;
        this.autoGen = autoGen;
    }

    /**
     * 获取value的字符串值, 为null时返回空字符串
     */
    public String getValueStrOrEmpty() {
        return value == null ? "" : value.toString();
    }

    /**
     * 获取value的字符串值, 为null时返回null
     */
    public String getValueStrOrNull() {
        return value == null ? null : value.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        KeyValue keyValue = (KeyValue) o;

        return Objects.equals(key, keyValue.key);

    }

    @Override
    public int hashCode() {
        return key != null ? key.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "KeyValue{" + "key='" + key + ", value=" + value + '}';
    }
}
